]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add shell_texture_cache_pixbufs_equal
authorColin Walters <walters@verbum.org>
Tue, 1 Sep 2009 18:13:15 +0000 (14:13 -0400)
committerColin Walters <walters@verbum.org>
Wed, 2 Sep 2009 18:54:49 +0000 (14:54 -0400)
Mutter is currently creating separate pixbufs for window icons;
use this to analyze them.

src/shell-texture-cache.c
src/shell-texture-cache.h

index 0ed3446d6893faa13161701481763d7437313bce..93835afb8088a395028f6fd93648a398ff8b1d7d 100644 (file)
@@ -1236,6 +1236,35 @@ shell_texture_cache_evict_recent_thumbnail (ShellTextureCache *cache,
   shell_texture_cache_evict_thumbnail (cache, gtk_recent_info_get_uri (info));
 }
 
+static size_t
+pixbuf_byte_size (GdkPixbuf *pixbuf)
+{
+  /* This bit translated from gtk+/gdk-pixbuf/gdk-pixbuf.c:gdk_pixbuf_copy.  The comment
+   * there was:
+   *
+   * Calculate a semi-exact size.  Here we copy with full rowstrides;
+   * maybe we should copy each row individually with the minimum
+   * rowstride?
+   */
+  return (gdk_pixbuf_get_height (pixbuf) - 1) * gdk_pixbuf_get_rowstride (pixbuf) +
+    + gdk_pixbuf_get_width (pixbuf) * ((gdk_pixbuf_get_n_channels (pixbuf)* gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8);
+}
+
+/**
+ * shell_texture_cache_pixbuf_equal:
+ *
+ * Returns: %TRUE iff the given pixbufs are bytewise-equal
+ */
+gboolean
+shell_texture_cache_pixbuf_equal (ShellTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b)
+{
+  size_t size_a = pixbuf_byte_size (a);
+  size_t size_b = pixbuf_byte_size (b);
+  if (size_a != size_b)
+    return FALSE;
+  return memcmp (gdk_pixbuf_get_pixels (a), gdk_pixbuf_get_pixels (b), size_a) == 0;
+}
+
 static ShellTextureCache *instance = NULL;
 
 /**
index 940e1010f35a59d6f82b0ecd25a987c165a2741a..057eae35381456d9ffe3563e3130a9eeec29667b 100644 (file)
@@ -79,4 +79,6 @@ ClutterActor *shell_texture_cache_load_uri_sync (ShellTextureCache *cache,
                                                  int                available_height,
                                                  GError           **error);
 
+gboolean shell_texture_cache_pixbuf_equal (ShellTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
+
 #endif /* __SHELL_TEXTURE_CACHE_H__ */